/**   
* @Description: TODO(用一句话描述该文件做什么) 
* @author thomas_liu 
* @date 2017年3月15日 下午8:45:30 
* @version V1.0   
*/
package com.thomas.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.thomas.entity.Blogger;
import com.thomas.service.BloggerService;
import com.thomas.util.CryptographyUtil;

/** 
 * @ClassName: BloggerController 
 * @Description: 博主Controller层
 * @author thomas_liu  
 * @date 2017年3月15日 下午8:45:30 
 *  
 */
@Controller
@RequestMapping("/blogger")
public class BloggerController {
	
	@Autowired
	private BloggerService bloggerService;
	
	@RequestMapping("/login")
	public String login(Blogger blogger,HttpServletRequest request){
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(blogger.getUserName(), CryptographyUtil.md5(blogger.getPassword(), "thomas"));
		try {
			subject.login(token);//登录验证
			return "redirect:/admin/main.jsp";
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("blogger", blogger);
			request.setAttribute("errorInfo", "用户名或者密码错误！");
			return "login";
		}
	}
	
	/**
	 *关于博主
	 *@return
	 *@throws Exception 
	 */
	@RequestMapping("/aboutMe")
	public ModelAndView aboutMe()throws Exception{
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageTitle", "关于博主_java开源博客系统");
		mav.addObject("mainPage", "foreground/blogger/info.jsp");
		mav.setViewName("mainTemp");
		return mav;
	}
}
